define(['util/mixinAjax'], function(mixinAjax) {
    const METHOD = 'GET';
    const JSON = 'json';
    const CONTENT_TYPE = 'application/json;charset=utf-8';

    function ajax (opt) {
        const option = {};

        if (opt.url) {
            option.url = mixinAjax.createUrl(opt.url, opt)
        } else {
            throw new Error(`${url} is required`)
        }

        if (opt.type === JSON || !opt.type) {
            option.contentType = CONTENT_TYPE;
            option.dataType = JSON;
        } else {
            option.contentType = opt.contentType;
            option.dataType = opt.dataType;
        }

        option.type = opt.method ? opt.method.toUpperCase() : METHOD;

        if (option.type === 'GET') {
            delete option.data
        }
        if (opt.method === 'POST') {
            option.data = opt.data || {}
        }


        option.headers = mixinAjax.createHeaders(option, opt.headers);

        /*
        * {
        *   headers: {
        *   headers: {},
        *   contentType: "application/json;charset=utf-8",
        *   dataType: "json",
        *   data: { id:"1" },
        *   url: xqurl+row.id,
        *   type: "get",
        *   success: function (data) {}
        * }
        * */
        return $.ajax(option);
    }

    return ajax
});
